//配置参考https://cli.vuejs.org/zh/config/ 官方
//https://www.cnblogs.com/jing-tian/p/11266796.html  例子
// https://www.jianshu.com/p/b8d934d4a84e 外部依赖
//https://www.cnblogs.com/zxuedong/p/12809234.html


// 获取外部库
function getProdExternals() {
	return {
		/* "xue.min.js" : "xue", */
		'axios' : 'axios'
		,'vue' : 'Vue'
		,'vant' : 'Vant'
		,'vue-router' : 'VueRouter'
		// , 'mint-ui' : 'mint-ui'
	    ,'jquery' :'jQuery'
	};
}

//打包为zip https://blog.csdn.net/liuliuliuliumin123/article/details/107840197
const FileManagerPlugin = require("filemanager-webpack-plugin"); //引入
const packageName = 'dist';

//
let pluginsArry=[];
let externals={};
if(process.env.VUE_APP_ENV === 'production'){//发布时打包

   externals=getProdExternals();
   
   pluginsArry.push(
         new FileManagerPlugin({ //打包为dist.zip
              onEnd: {
                delete: [   //首先需要删除项目根目录下的dist.zip
                  `./${packageName}.zip`,   
                ],
                archive: [ //然后我们选择dist文件夹将之打包成dist.zip并放在根目录
                  {source: `./${packageName}`, destination: `./${packageName}.zip`},   
                ]
              }
        })
    )
}


module.exports = {
	 publicPath : process.env.VUE_APP_WEB_URL
	,assetsDir: 'static/app'
	//生产环境是否生成 sourceMap 文件
	,productionSourceMap : false
	,pages : { // https://www.cnblogs.com/jing-tian/p/11266796.html
	      index :
	      {
        	  entry    : 'src/main.js', 
        	  template : 'public/index.html', 
        	  filename : 'index.html', title : '家校飞雁', 
        	  chunks   : ['chunk-vendors', 'chunk-common','index'] 
	      }
	     ,
	    /* index1 :
         {
             entry    : 'src/TestMain.js', 
             template : 'public/index1.html', 
             filename :'index1.html', title : '首页', 
             chunks: ['chunk-vendors', 'chunk-common','index1'] 
         }*/
	}
	
	//================webpakc config======================================
	,configureWebpack : {//对象模式或函数模式配置webpack
         name:"p2pp管理系统"
        ,externals : externals
        ,resolve : {
            alias : {
                // 别名
                  vue$          : "vue/dist/vue.js"
                 ,vant$         : "vant/lib/vant.js"
                 ,'vue-router$' : "vue-router/dist/vue-router.js"
            }
        }
      ,devServer:{
          port:process.env.PORT||8080
          ,watchOptions: {
                  //ignored: [/node_modules/, /public/],
                  //ignored: ['public/pages/**', 'node_modules/**','dist.zip',]
          }
      }
      ,plugins: [...pluginsArry]
        
    }
    /*
    ,chainWebpack: config => {
        
        config.plugin('html').tap(args => {
            args[0].title = '八维家校通'
            return args
        })
    }
    */
    

    //================webpakc config  end======================================

}
